package com.springboot.codeminestarter.codemine.business.role.controller;

import com.springboot.codeminestarter.codemine.aop.log.LogWrite;
import com.springboot.codeminestarter.codemine.business.role.domain.SysRole;
import com.springboot.codeminestarter.codemine.business.role.service.RoleService;
import com.springboot.codeminestarter.codemine.domain.ResponseWrapper;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@Tag(name = "角色模块")
@RestController
@RequestMapping("/role")
public class RoleController {

    @Autowired
    private RoleService roleService;

    /**
     * 获取角色列表
     */
    @LogWrite(value = "获取角色列表")
    @GetMapping("/getRoleList")
    public ResponseWrapper getRoleList() {

        return ResponseWrapper.Success(roleService.getRoleList());
    }

    /**
     * 根据UserId获取角色列表
     */
    @LogWrite(value = "根据UserId获取角色")
    @GetMapping("/getRoleList/{userId}")
    public ResponseWrapper getRoleListByUserId(@PathVariable String userId) {

        return ResponseWrapper.Success(roleService.getRoleListByUserId(userId));
    }

    /**
     * 新增角色
     */
    @LogWrite(value = "新增角色")
    @PostMapping("/addRole")
    public ResponseWrapper addRole(@RequestBody SysRole role) {
        roleService.addRole(role);
        return ResponseWrapper.Success();
    }

}
